import java.util.Arrays;

public class MyStack {
    int[] elem;
    public int usedSize;

    public MyStack() {
        this.elem = new int[2];
    }

    public void push(int val) {
        if(isFull()) {
            this.elem = Arrays.copyOf(elem,2*elem.length);
        }
        elem[usedSize] = val;
        usedSize++;
    }

    public boolean isFull() {
        return usedSize == elem.length;
    }

    public boolean isEmpty() {
        return this.usedSize == 0;
    }
    public int pop() {
        if(isEmpty()) {
            throw new EmptyException("栈为空！");
        }

        int topData = this.elem[usedSize - 1];
        this.usedSize--;
        return topData;
    }

    public int getTop() {
        if(isEmpty()) {
            throw new EmptyException("栈为空！");
        }

        int topData = this.elem[usedSize - 1];
        return topData;
    }

    public static void main(String[] args) {
        MyStack stack = new MyStack();
        stack.push(1);
        stack.push(2);
        stack.push(3);
        stack.push(4);
        System.out.println(stack.pop());
        System.out.println(stack.getTop());

    }
}
